package com.design.composite.org;

import java.util.ArrayList;
import java.util.List;

// 部门类，实现了组件接口
class Department implements Component {
    private String name;
    private List<Component> employees = new ArrayList<>();

    public Department(String name) {
        this.name = name;
    }

    public void addEmployee(Component employee) {
        employees.add(employee);
    }

    @Override
    public void display() {
        System.out.println("Department: " + name);
        for (Component employee : employees) {
            employee.display();
        }
    }

    @Override
    public double getSalary() {
        double totalSalary = 0;
        for (Component employee : employees) {
            totalSalary += employee.getSalary();
        }
        return totalSalary;
    }
}
